package model

import "nodemessage.com/codetool/logic"

type ConfGenCode struct {
	logic.JavaMeta `mapstructure:"meta"`
	Db             struct {
		UserName  string   `mapstructure:"userName"`
		Password  string   `mapstructure:"password"`
		Host      string   `mapstructure:"host"`
		Port      int      `mapstructure:"port"`
		DataBase  string   `mapstructure:"dataBase"`
		Tables    []string `mapstructure:"tables"`
		tablesMap map[string]string
	} `mapstructure:"db"`
}

func (c ConfGenCode) ExistTable(table string) (exist bool) {
	if c.Db.tablesMap == nil {
		c.Db.tablesMap = make(map[string]string)
		for _, s := range c.Db.Tables {
			c.Db.tablesMap[s] = s
		}
	}
	if len(c.Db.tablesMap) == 0 {
		exist = true
	} else {
		_, exist = c.Db.tablesMap[table]
	}
	return
}
